package cn.iocoder.yudao.module.wrdk.service.grid;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.wrdk.controller.admin.grid.vo.*;
import cn.iocoder.yudao.module.wrdk.dal.dataobject.grid.wrdkgridDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.wrdk.convert.grid.wrdkgridConvert;
import cn.iocoder.yudao.module.wrdk.dal.mysql.grid.wrdkgridMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.wrdk.enums.ErrorCodeConstants.*;

/**
 * 地块坐标 Service 实现类
 *
 * @author Fan Kaixiang
 */
@Service
@Slf4j
@Validated
public class wrdkgridServiceImpl implements wrdkgridService {

    @Resource
    private wrdkgridMapper wrdkgridMapper;

    @Override
    public Long createwrdkgrid(wrdkgridCreateReqVO createReqVO) {
        // 插入
        wrdkgridDO wrdkgrid = wrdkgridConvert.INSTANCE.convert(createReqVO);
        wrdkgridMapper.insert(wrdkgrid);
        // 返回
        return wrdkgrid.getId();
    }

    @Override
    public void updatewrdkgrid(wrdkgridUpdateReqVO updateReqVO) {
        // 校验存在
        this.validatewrdkgridExists(updateReqVO.getId());
        // 更新
        wrdkgridDO updateObj = wrdkgridConvert.INSTANCE.convert(updateReqVO);
        wrdkgridMapper.updateById(updateObj);
    }

    @Override
    public void deletewrdkgrid(Long id) {
        // 校验存在
        this.validatewrdkgridExists(id);
        // 删除
        wrdkgridMapper.deleteById(id);
    }

    private void validatewrdkgridExists(Long id) {
        if (wrdkgridMapper.selectById(id) == null) {
            throw exception(WRDKGRID_NOT_EXISTS);
        }
    }

    @Override
    public wrdkgridDO getwrdkgrid(Long id) {
        return wrdkgridMapper.selectById(id);
    }

    @Override
    public List<wrdkgridDO> getwrdkgridList(Collection<Long> ids) {
        return wrdkgridMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<wrdkgridDO> getwrdkgridPage(wrdkgridPageReqVO pageReqVO) {
        return wrdkgridMapper.selectPage(pageReqVO);
    }

    @Override
    public List<wrdkgridDO> getwrdkgridList(wrdkgridExportReqVO exportReqVO) {
        return wrdkgridMapper.selectList(exportReqVO);
    }

}
